﻿using BootstrapBlazor.Components;
using BPM.Web.Shared.Data;
using BPM.Web.Shared.Dependencies;
using BPM.Web.Shared.Extensions;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Http;
using WebApiClientCore.Parameters;

namespace BPM.Web.Shared.Service;

[Scoped(typeof(ISysFileService))]
public class SysFileService : BaseService, ISysFileService
{
    private readonly IFileClient _fileClient;
    public SysFileService(IFileClient fileClient, ToastService toast) : base(toast)
        => _fileClient = fileClient;

    public Task<QueryData<FileOutput>> PageAsync(FilePageInput input)
        => QueryAsync(_fileClient.PageAsync(input));

    public Task<List<SysFile>?> ListAsync(FileOutput input)
        => QueryAsync<List<SysFile>>(_fileClient.ListAsync(input));

    public Task<bool> DeleteAsync(IEnumerable<FileOutput> input)
        => DeleteAsync(input.Adapts<FileOutput, DeleteFileInfoInput>().Select(x => _fileClient.DeleteAsync(x)));

    public Task<SysFile?> DetailAsync(QueryFileInfoInput input)
        => QueryAsync(_fileClient.DetailAsync(input));

    public async Task<HttpResponseMessage> PreviewAsync(QueryFileInfoInput input)
      => await _fileClient.PreviewAsync(input);

    public Task<long> UploadAsync(FormDataFile input)
        => ExecuteAsync(_fileClient.UploadAsync(input));

    public async Task<HttpResponseMessage> DownloadAsync(QueryFileInfoInput input)
      => await _fileClient.DownloadAsync(input);

    public Task<long> UploadAvatarAsync(FormDataFile input)
        => ExecuteAsync(_fileClient.UploadAvatarAsync(input));

    public Task<string?> UploadDocumentAsync(FormDataFile input)
        => ExecuteAsync<string>(_fileClient.UploadDocumentAsync(input));

    public Task<string?> UploadShopAsync(FormDataFile input)
        => ExecuteAsync<string>(_fileClient.UploadShopAsync(input));
}

